package Terminal.UI;


import java.awt.Dimension;
import java.awt.GridLayout;

import javax.swing.JPanel;

public class OptionPanelVertical extends PanelComponent{
	private GridLayout gridlay; 
	
	public OptionPanelVertical(PanelComponent parent){
		super(parent);
		pannellocomponente= new JPanel(/*new GridLayout()*/null);
		}
	
	public JPanel createComponents(){
		return pannellocomponente ;
	}

	public void add(PanelComponent figlio) {
		super.add(figlio);
		pannellocomponente.add(figlio.createComponents());	
		updateSize();
	}
	
	public void addPosition(PanelComponent figlio, int y){
		super.add(figlio);
		JPanel paneltemp= figlio.createComponents();
		//Dimension size = figlio.getSize();
		paneltemp.setBounds(0,y,figlio.getSize().width,figlio.getSize().height);
	
		pannellocomponente.add(paneltemp);
		
		updateSize();
		pannellocomponente.validate();
		
	}
	
	public void remove(int index ){
		super.remove(index);
		pannellocomponente.remove(index);
	}
	

	
	public void updateSize(){
		size_width=0;
		size_height=0;
		int i=0;
		Dimension d= new Dimension(size_width,size_height);
		/*for(Component c:pannellocomponente.getComponents()){
			System.out.print("\nop"+c.getClass().toString()+c.getSize().width+" "+c.getLocation().x);
			size_width=size_width+c.getSize().width+c.getLocation().x;
			if(size_height<d.height){size_height=d.height;}
			System.out.print("\n"+size_height+" "+size_width);
			//i++;
		}
		*/
		
		/*for (Map.Entry<String, PanelComponent> pcelement: children.entrySet()) {
			d=((PanelComponent) pcelement.getValue()).getSize();
			System.out.print("\n"+size_width+" "+d.width+" "+pannellocomponente.getComponent(i).getLocation().x);
			size_width=size_width+d.width+pannellocomponente.getComponent(i).getLocation().y;
			if(size_height<d.height){size_height=d.height;}
			i++;
		}*/
		for (PanelComponent pcelement: children) {
			d=pcelement.getSize();
			size_height=size_height+d.height+pannellocomponente.getComponent(i).getLocation().y;
			if(size_width<d.width){size_width=d.width;}//*/
		//	if(d.width+pannellocomponente.getComponent(i).getLocation().x>size_width) size_width=d.width+pannellocomponente.getComponent(i).getLocation().x;
		//	if(size_height<d.height) size_height=d.height;
		//	System.out.print("\nop"+size_width+" "+size_height);
			i++;
		}
		this.setSize(size_width, size_height);
		
		if(parent!=null)parent.updateSize();
	}
	public void setSize(int width, int height){
		super.setSize(width, height);
		for (PanelComponent pcelement: children) {
			pcelement.setSize(width,pcelement.getSize().height);
		}
	}

}
